<?php
error_reporting(0);

$资源接口 = 'https://api.wujinapi.me/api.php/provide/vod/from/wjm3u8/at/xml/';

// 获取分类XML数据
$分类数据 = file_get_contents($资源接口);
$fenleixml = simplexml_load_string($分类数据, 'SimpleXMLElement', LIBXML_NOCDATA);
// 获取XML数据
$categoryList = [];
foreach ($fenleixml->class->ty as $category) {
    $categoryList[] = [
        'id' => (int)$category['id'],
        'name' => (string)$category,
    ];
}

// 创建XML格式的字符串
$资源分类XML = "";
foreach ($categoryList as $category) {
    $资源分类XML .= "<ty id=\"" . $category['id'] . "\">" . $category['name'] . "</ty>\n";
}

// 将分类数组转换为JSON，并进行替换
// $资源分类1 = json_encode(htmlspecialchars($资源分类XML));
$资源分类1 = htmlspecialchars($资源分类XML);
$资源分类2 = strtr($资源分类1, array('\''=>'"', '<ty id="'=>',{"分类号":"', '">'=>'","分类名":"', '</ty>'=>'"}'));
$资源分类3 = '[{"分类号":"","分类名":"最近更新"}' . $资源分类2 . ']';

// 解码JSON字符串并分配给变量
$分类 = json_decode($资源分类3, TRUE);

print_r($分类);

// echo htmlspecialchars($资源分类XML);






// 获取分类XML数据
$分类数据 = file_get_contents($资源接口);
$fenleixml = simplexml_load_string($分类数据, 'SimpleXMLElement', LIBXML_NOCDATA);
// 获取XML数据
$categoryList = [];
foreach ($fenleixml->class->ty as $category) {
    $categoryList[] = [
        'id' => (int)$category['id'],
        'name' => (string)$category,
    ];
}
// 创建XML格式的字符串
$资源分类XML = "";
foreach ($categoryList as $category) {
    $资源分类XML .= "<ty id=\"" . $category['id'] . "\">" . $category['name'] . "</ty>";
}
//处理资源分类
$资源分类=strtr($资源分类XML,array('\''=>'"','<ty id="'=>',{"分类号":"','">'=>'","分类名":"','</ty>'=>'"}'));
$资源分类='[{"分类号":"","分类名":"最近更新"}'.$资源分类.']';$分类=json_decode($资源分类,TRUE);
//print_r($资源分类);exit;

?>